import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import static javax.swing.JFrame.*;
public class WindowBeijing extends JFrame { 
   JTextField text1,text2,text3;
   InnerPolice police;    //内部类声明的对象
   public WindowBeijing() {
      init();
      setBounds(100,100,350,150);
      setVisible(true);
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   }
   void init() {
      setLayout(new FlowLayout());
      text1=new JTextField(10);
      text2=new JTextField(10); 
      text3=new JTextField(10);          
      police=new InnerPolice();
      text1.addActionListener(police); //内部类实例做监视器
      text2.addActionListener(police); //内部类实例做监视器
      text3.addActionListener(new ActionListener() {  //匿名类实例做监视器
                                     public void actionPerformed(ActionEvent e) {
                                        String str=text3.getText();
                                        if(str.equalsIgnoreCase("Exit")) 
                                           System.exit(0);
                                     }
                                  }
                                 
                             ); 
      add(text1); 
      add(text2);
      add(text3);
   }
   class  InnerPolice implements ActionListener {  //内部类
      public void actionPerformed(ActionEvent e) { 
         if(e.getSource()==text1) {
             text2.setText(""+text1.getText().length());
         }
         else if(e.getSource()==text2) {
            boolean boo=text2.getText().contains(text1.getText());
            text3.setText(""+boo) ;
         }
      }
   }
}

